/**
 * 
 */
package config.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.jdbc.core.JdbcTemplate;

import com.sany.util.JDBCUtil;
import com.sany.util.log.ILogger;

import config.view.ListDecorator;

/**
 * @author chenzh
 * Oct 21, 2009
 */
public class MonitorAction extends DispatchAction {
	private static final ILogger log = ILogger.getInstance().getILogger(MonitorAction.class);

	/**
	 * 
	 * Oct 21, 2009
	 * chenzh
	 * TODO
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward monitorLogList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		JdbcTemplate jt = JDBCUtil.getJdbcTemplate();
		String key_ = request.getParameter("key_");
		String type_ = request.getParameter("type_");
		StringBuffer sb = new StringBuffer();
		if(key_!=null && !key_.equals("")){
			sb.append(" where key_='" + key_ + "'");
		}
		if(type_!=null && !type_.equals("")){
			sb.append(" where type_='" + type_ + "'");
		}
		//String sql = "select top 2000 * from mam_monitorlog "+ sb.toString() +" order by id desc";
		String sql = "select   c.id,c.ip,c.date_,c.key_,c.name_,c.value_,c.mark_,c.type_,c.level_,c.user_  from ("+
				"select rownum as  b,a.id,a.ip,a.date_,a.key_,a.name_,a.value_,a.mark_,a.type_,a.level_,a.user_ from mam_monitorlog  a " +
					sb.toString()+"  order by id desc) c where c.b<2001";	 
		List list = jt.queryForList(sql, new Object[]{});
		request.setAttribute("list", new ListDecorator().getMonitorLogList(list));
		return mapping.findForward("index");
	}
}
